
package com.haodai.agency.net;

import android.content.Intent;

import com.alibaba.fastjson.JSON;
import com.haodai.agency.MainActivity;
import com.haodai.agency.application.MyApplication;
import com.haodai.agency.login.activity.LogInActivity;
import com.haodai.agency.net.bean.ResultEntity;
import com.haodai.agency.save.SaveSharedPreferences;
import com.haodai.agency.save.UserSharedPreferences;
import com.haodai.agency.utils.AESCrypt;
import com.haodai.agency.utils.Logs;

import org.json.JSONException;
import org.json.JSONObject;

import rx.Observer;

/**
 * Created by fanday on 2017/3/16.
 */
public abstract class MyObserver<T> {

    private static final String TAG = MyObserver.class.getSimpleName();

    public Observer creatObserver() {
        return new Observer<ResultEntity<String>>() {
            @Override
            public void onCompleted() {
                MyObserver.this.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
                MyObserver.this.onError(e);
            }

            @Override
            public void onNext(ResultEntity<String> o) {
                if(o.isEncrypt()){//isEncrypt对应是否是加密字段
                    String decrypt = AESCrypt.getInstance().decrypt(o.getData());
                    o.setData(decrypt);
                }
                MyObserver.this.onNext(o);
            }
        };
    }
    public abstract void onNext(ResultEntity<String> resultEntity);
    public abstract void onError(Throwable e);
    public abstract void onCompleted();

}
